package com.example.animationdemo;

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ObjectAnimatorActivity extends Activity {
    private static final String TAG = "ObjectAnimatorActivity";
    private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_obj_animator);
        tv = findViewById(R.id.tv);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator.ofFloat(tv, "translationY", tv.getHeight()).start();
            }
        });

        /** 改变颜色 **/
        /*ValueAnimator colorAnimator = ObjectAnimator.ofInt(tv, "backgroundColor", 0xFFFF8080, 0xFF8080FF);
        colorAnimator.setDuration(3000);
        colorAnimator.setEvaluator(new ArgbEvaluator());
        colorAnimator.setRepeatCount(ValueAnimator.INFINITE);
        colorAnimator.setRepeatMode(ValueAnimator.REVERSE);
        colorAnimator.start();*/

        /** 动画集合 **/
        /*AnimatorSet set = new AnimatorSet();
        set.playTogether(
                ObjectAnimator.ofFloat(tv, "rotationX", 0, 360),
                ObjectAnimator.ofFloat(tv, "rotationY", 0, 180),
                ObjectAnimator.ofFloat(tv, "rotation", 0, -90),
                ObjectAnimator.ofFloat(tv, "translationX", 0, 90),
                ObjectAnimator.ofFloat(tv, "translationY", 0, 90),
                ObjectAnimator.ofFloat(tv, "scaleX", 1, 1.5f),
                ObjectAnimator.ofFloat(tv, "scaleY", 1, 0.5f),
                ObjectAnimator.ofFloat(tv, "alpha", 1, 0.25f, 1)

        );
        set.setDuration(5 * 1000).start();*/



        AnimatorSet propertyAnimatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.property_animator);
        propertyAnimatorSet.setTarget(tv);
        propertyAnimatorSet.start();
    }

}
